import tkinter as tk

'简易GUI工具'
__author__ = 'littleHuang'
'''
为减少GUI编写的复杂度而编写的父类, 使用时继承即可
接口比较死板，且只实现了一些简单的功能，使用网格布局方式
'''


class EasyGui:
    def __init__(self):
        self.fatherWindow = tk.Tk()
        # 字体设置
        self.font = ('SimHei', 12)

    def setWindowName(self, name=''):
        '''
        :param name: 窗口名
        :return:
        '''
        self.fatherWindow.title(name)

    def setLabel(self, text='', width=1, row=0, column=0, columnspan=1):
        '''
        :param text: 标签内容
        :param width: 标签宽度
        :param row: 放置行
        :param column: 放置列
        :param columnspan: 合并列
        :param sticky: 调整位置
        :return:
        '''
        tk.Label(self.fatherWindow, text=text, width=width, font=self.font).grid(row=row, column=column,
                                                                                 columnspan=columnspan, )

    def setButton(self, text='', width=1, command=None, row=0, column=0, columnspan=1):
        '''
        :param text:
        :param width:
        :param command: 按下按钮后执行的函数
        :param row:
        :param column:
        :param columnspan:
        :param sticky:
        :return: 按键对象
        '''
        b = tk.Button(self.fatherWindow, text=text, width=width, command=command, font=self.font)
        b.grid(row=row, column=column, columnspan=columnspan)
        return b

    def setEntry(self, width=1, row=0, column=0, columnspan=1):
        '''
        :param width:
        :param row:
        :param column:
        :param columnspan:
        :param sticky:
        :return: 输入框对象
        '''
        e = tk.Entry(self.fatherWindow, width=width, font=self.font)
        e.grid(row=row, column=column, columnspan=columnspan)
        return e

    def setText(self, width=1, height=1, row=0, column=0, columnspan=1):
        '''
        :param width:
        :param height: 文本框高度
        :param row:
        :param column:
        :param sticky:
        :param columnspan:
        :return: 文本框对象
        '''
        t = tk.Text(self.fatherWindow, width=width, height=height, font=self.font)
        t.grid(row=row, column=column, columnspan=columnspan)
        return t

    def setRadiobutton(self, text='', value='', var=None, row=0, column=0, columnspan=1):
        '''
        :param text:
        :param value: 可变字符串点击后的设定值
        :param var: 可变字符串
        :param row:
        :param column:
        :param sticky:
        :param columnspan:
        :return:
        '''
        tk.Radiobutton(self.fatherWindow, text=text, variable=var, value=value, font=self.font).grid(row=row,
                                                                                                     column=column,
                                                                                                     columnspan=columnspan)

    def run(self):
        self.fatherWindow.mainloop()
